package ruler.rules;

import java.util.HashMap;

import android.os.Parcel;
import android.os.Parcelable;

public class appRunningRule extends Rule {

	public appRunningRule() {
		super();
	}

	public appRunningRule(String n) {
		super(n);
	}

	public appRunningRule(int id, String name, String description,
			DEVICE_TYPE device_type, RULE_TYPE rule_type, String packageName,
			boolean whenRunning, boolean enable_device) {
		super(id, name, description, device_type, rule_type, packageName,
				whenRunning, enable_device);
	}

	public appRunningRule(Rule rule) {
		super(rule);
	}

	public boolean isValid(HashMap<String, RULE_TYPE> hasMap) {
		boolean isRunning = hasMap.containsKey(this.packageName)
				&& hasMap.get(this.packageName).equals(this.rule_type);
		if ((isRunning && this.whenRunning)
				|| (!isRunning && !this.whenRunning)) {
			return true;
		} else {
			return false;
		}
	}

	public appRunningRule(Parcel in) {
		super(in);
	}

	public static final Parcelable.Creator<appRunningRule> CREATOR = new Parcelable.Creator<appRunningRule>() {
		public appRunningRule createFromParcel(Parcel in) {
			return new appRunningRule(in);
		}

		public appRunningRule[] newArray(int size) {
			return new appRunningRule[size];
		}
	};
}
